//
//  ViewController.m
//  04-UIControl
//
//  Created by dllo on 16/7/19.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    self.view.backgroundColor= [UIColor blackColor];
    // Do any additional setup after loading the view, typically from a nib.
    // UISwitch（开关）
    // Switch 宽高不影响控件 ， 只有x和y
    UISwitch *switchControl = [[UISwitch alloc] initWithFrame:CGRectMake(10, 100, 0, 0)];
    [self.view addSubview:switchControl];
    //1.开启时的控件内部颜色
    switchControl.onTintColor = [UIColor yellowColor];
    //2.边框及切换到关闭时的颜色 (null_resettable)
    switchControl.tintColor = nil;
    //3.开关按钮（圆圈）的颜色
    switchControl.thumbTintColor = [UIColor blackColor];
    //4.打开时的图片，iOS7后失效
    switchControl.onImage = [UIImage imageNamed:@"question 20-36-53-426.png"];
    //5.关闭时的图片，iOS7后失效
    switchControl.offImage = [UIImage imageNamed:@"question 20-36-53-426.png"];
    //6.判断switchControl的开闭状态 NO 为 关闭状态 YES 为 开启状态
    //通过setter方法， 改变switchControl的初始状态
    switchControl.on = YES;
    NSLog(@"%@", switchControl.isOn ? @"YES" : @"NO");
    [switchControl setOn:YES animated:YES];
    //7.添加绑定(与button相同)
    [switchControl addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
   
    //UISlider
    //高度不影响控件的高度， 这个控件永远居中与试图中间
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(10, 50, 300, 50)];
    [self.view addSubview:slider];
   // 1. 当前滑块的值
    slider.value = 0.5f;
    NSLog(@"%f", slider.value);
   // 2.滑块的最小值 0.0
    slider.minimumValue = 0.0f;
    // 3.滑块的最大值 1.0
    slider.maximumValue = 1.0f;
    NSLog(@"%f", slider.minimumValue);
    NSLog(@"%f", slider.maximumValue);
   // 4.minimumValueImage  slider 在最小值的那一边的图片
    slider.minimumValueImage = [UIImage imageNamed:@"question 20-36-53-426.png"];
    // 5. maximumValueImage  slider 在最大值的那一边的图片
    slider.maximumValueImage = [UIImage imageNamed:@"question 20-36-53-426.png"];
    //6.YES时当value变化时连续触发事件，NO时当value变化时当手指离开时才触发事件
    slider.continuous = NO;
    //7. 添加事件
    [slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
    // 8.minimumTrackTintColor 未移动到的区域颜色
//    slider.minimumTrackTintColor = [UIColor yellowColor];
    //9.maximumTrackTintColor 移动到的区域颜色
//    slider.maximumTrackTintColor = [UIColor redColor];
    //10.slider 滑块的颜色
//    slider.thumbTintColor = [UIColor cyanColor];
   //11. 设置进度条滑块左边的图片
    [slider setMaximumTrackImage:[UIImage imageNamed:@"player_slider_playback_right"] forState:UIControlStateNormal];
    //12. 设置进度条滑块右边的图片
    [slider setMinimumTrackImage:[UIImage imageNamed:@"player_slider_playback_left"] forState:UIControlStateNormal];
    //13. 设置进度条滑块图片
    [slider setThumbImage:[UIImage imageNamed:@"player_slider_playback_thumb"] forState:UIControlStateNormal];
    
  //UISegmentedControl
    UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithItems:@[@"first", @"second", @"third"]];
    segmentControl.frame = CGRectMake(20, 20, 335, 50);
    //segment不给frame ， 系统自动计算大小 （推荐加上frame）
    NSLog(@"%@", NSStringFromCGRect(segmentControl.frame));
   //    1.momentary 设置为YES， 如果点击选中没有选中效果 （默认为NO）
    segmentControl.momentary = YES;
    segmentControl.tag = 1000;
   //  2.numberOfSegments
    NSInteger numberOfSegments = segmentControl.numberOfSegments;
    NSLog(@"分段控制器Items的个数%ld", numberOfSegments);
    
    UIButton *addTitleButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 200, 100, 50)];
//    addTitleButton.font = [UIFont systemFontOfSize:12];
    addTitleButton.backgroundColor = [UIColor redColor];
    [addTitleButton setTitle:@"点击添加标题" forState:UIControlStateNormal];
    [addTitleButton addTarget:self action:@selector(addTitleButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:addTitleButton];
   //3.insertSegmentWithTitle:atIndex:animated:
   //4.remove
   //5.setTitle:forSegmentAtIndex: 用来修改对应下标的标题
   //[segment setTitle:@"sdsd" forSegmentAtIndex:0];
   // 6.  - (void)setWidth:(CGFloat)width forSegmentAtIndex:(NSUInteger)segment;  设置个别item的宽度
  //7.etContentOffset: forSegmentAtIndex:设置对应下标内容的偏移
    [segmentControl setContentOffset:CGSizeMake(0, 20) forSegmentAtIndex:0];
    [segmentControl setWidth:0 forSegmentAtIndex:1];
  //8.setEnabled:forSegmentAtIndex: 是否能被被选中    [segmentControl setEnabled:NO forSegmentAtIndex:2];
  //9.selectedSegmentIndex 选中的下标
    segmentControl.selectedSegmentIndex = 1;
  //10.tintColor 文字和边框的颜色
    segmentControl.tintColor = [UIColor blackColor];
  // 11.如果分段控制器的段宽为0时， 并且该属性为YES， 系统会自动计算
    segmentControl.apportionsSegmentWidthsByContent = YES;
   //12 segment 绑定事件
    [segmentControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:segmentControl];
    
    //UIPageControl
    UIPageControl *page = [[UIPageControl alloc] initWithFrame:CGRectMake(20, 300, 350, 100)];
//    page.backgroundColor = [UIColor redColor];
   //1. 分页控制器的页数 总页数 默认为0
    page.numberOfPages = 5;
   //3. 当前页
    page.currentPage = 3;
   //4.hidesForSinglePage 当只有一页时 隐藏
//    page.hidesForSinglePage = YES;
   // 获取到点的大小
  CGSize size = [page sizeForNumberOfPages:0];
    NSLog(@"%@", NSStringFromCGSize(size));
// 5. 未选中页的颜色
    page.backgroundColor = [UIColor orangeColor];
    page.pageIndicatorTintColor = [UIColor cyanColor];
   // 6. 当前页的颜色
    page.currentPageIndicatorTintColor = [UIColor redColor];
    NSLog(@"%@", NSStringFromCGSize(size));
  //7. 绑定事件
    [page addTarget:self action:@selector(pageControlChange:) forControlEvents:UIControlEventValueChanged];
    
    
//  8 . 设置为YES，关闭系统事件配置的切换，直到调用updateCurrentPageDisplay的方法才会显示。
    page.defersCurrentPageDisplay = YES;
    [self.view addSubview:page];
    
    
}
- (void)pageControlChange:(UIPageControl *)pageControl {
    NSLog(@"chang");
//    [pageControl updateCurrentPageDisplay];
    
}

- (void)segmentAction:(UISegmentedControl *)segment {
    switch (segment.selectedSegmentIndex) {
        case 0:
            
            break;
        case 1:
            
            break;
        case 2:
            
            break;
        default:
            break;
    }
    
    NSLog(@"%ld", segment.selectedSegmentIndex);
}

- (void)addTitleButtonClicked:(UIButton *)button {
   
    UISegmentedControl *segment = [self.view viewWithTag:1000];
    [segment insertSegmentWithTitle:@"12" atIndex:3 animated:YES];
    [segment setTitle:@"sdsd" forSegmentAtIndex:0];
    
  
}

- (void)sliderAction:(UISlider *)slider {
    NSLog(@"%f", slider.value);
}


// switch 触发的事件
- (void) switchAction:(UISwitch *)switchControl {
  // 根据switch的状态， 决定触发什么样的事件
    if (switchControl.on == YES) {
        NSLog(@"开");
    } else {
        NSLog(@"关");
    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
